﻿function initRegister() {
    $(".putQuestion").hide();
    var btnRegister = $("#register-button");
    var cboQuestion1 = $("select[name=cboQuestion1]");
    var cboQuestion2 = $("select[name=cboQuestion2]");
    btnRegister.click(function () {
        $("span[class=notice]").remove();
        $("#hddKindSubmit").val("register");
        var isCheck=validateRegister() ;
        if (isCheck== true) { //return false;
            document.frmRegister.submit();
            
        }
    });
    cboQuestion1.change(function () {
        var len = $("select[name=cboQuestion1] option").size();
        var x = $(this).get(0).selectedIndex;
        var putQuestion1 = $(".putQuestion:eq(0)");
        if (x == len - 1) {
            putQuestion1.show();
        }
        else putQuestion1.hide()
        ;
    });
    cboQuestion2.change(function () {
        var len = $("select[name=cboQuestion2] option").size();
        var x = $(this).get(0).selectedIndex;
        var putQuestion2 = $(".putQuestion:eq(1)");
        if (x == len - 1) {
            putQuestion2.show();
        }
        else putQuestion2.hide()
        ;
    });
}
function validateRegister() {
    var isValidate = true;
    var x = $("#register-frame input[type=text]:visible");
    $("span[class=check]").remove();
    x.each(function () {
        if ($(this).val() == "") {
            $(this).after("<span class='check'>*</span>");
            isValidate = false;
        }
    });
    if (isValidate == false) return false;
    if (checkCapcha() == false) return false;
    
    if ($("#chkAgree").is(":checked")) isValidate = true;
    else {
        alert("Bạn chưa đồng ý với các điều khoản!");
        return false;
    }
    if (checkPassRecover() == false) return false;
    return true;
}
function checkCapcha() {
    var stringCapcha = $("span[class=capcha]").text();
    var text = $("input[id=txtCapcha]").val();
    if ($.trim(stringCapcha) != $.trim(text)) {
        $("input[id=txtCapcha]").after("<span class='notice'>Bạn chưa nhập đúng kí tự</span>");
        return false;
    }
    return true;
}
function checkPassRecover() {
    var pass = $("#txtPass").val();
    var passRecover = $("#txtPassRecord").val();
    if (pass != passRecover) {
        $("input[id=txtPassRecord]").after("<span class='notice'>Password chưa trùng lặp!</span>");
        return false;
    }
    return true;
}